package com.fqh.service.impl;

import com.fqh.entity.Diningtable;
import com.fqh.mapper.TableMapper;
import com.fqh.service.TableService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class TableServiceImpl implements TableService {

    @Autowired
    private TableMapper tableMapper;

    @Override
    public Integer findTableCount(String str) {
        Integer tableCount = tableMapper.findTableCount(str);
        return tableCount;
    }

    @Override
    public List<Diningtable> findByPage(int page, int limit, String search) {
        page = (page - 1) * limit;
        return tableMapper.findByPage(page, limit, search);
    }

    @Override
    public Integer findTotalCount(String search) {
        return tableMapper.findTotalCount(search);
    }

    @Override
    public void deleteTableByTableId(String tableId) throws Exception {
        tableMapper.deleteTableByTableId(tableId);
    }

    @Override
    public void addTable(String tableId) throws Exception {
        Diningtable diningtable = new Diningtable();
        diningtable.setTableId(tableId);
        diningtable.setTableState("空闲");
        tableMapper.addTable(diningtable);
    }

    @Override
    public Diningtable findTableByTableId(String tableId) {
        return tableMapper.findTableByTableId(tableId);
    }

    @Override
    public void updateTable(String tableId, String tableState) throws Exception {
        Diningtable diningtable = new Diningtable();
        diningtable.setTableState(tableState);
        diningtable.setTableId(tableId);
        tableMapper.updateTable(diningtable);
    }
}
